﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using ThreeByte.ActiveDeck.Config;
using PowerPoint = Microsoft.Office.Interop.PowerPoint;
using Excel = Microsoft.Office.Interop.Excel;
using ThreeByte.ActiveDeck.Data.UserResponse;
using ThreeByte.ActiveDeck.AddIn.Content.UserResponse;
using ThreeByte.Media;


namespace ThreeByte.ActiveDeck.Controls.UserResponse
{
    /// <summary>
    /// Interaction logic for CategoriesResponseConfiguration.xaml
    /// </summary>
    public partial class CategoriesResponseConfiguration : UserControl, IUserResponseConfigurationControl
    {

        private CategoriesConfig mConfig;

        public CategoriesResponseConfiguration(PageConfig config) {
            InitializeComponent();

            DataContext = config;
            mConfig = (CategoriesConfig)config;
        }

        public PowerPoint.Shape InsertUserResponseComponent(PowerPoint.Slide slide) {

            //TODO: Insert centered, at half the height/width of the slide
            float height = slide.Master.Height / 2.0f;
            float width = slide.Master.Width / 2.0f;

            //Snap a graphic / Insert that
           
            CategoriesDataUserControl2 newControl = new CategoriesDataUserControl2();
            newControl.Config = mConfig;
            CategoriesUserData userData = mConfig.InitUserData();
            newControl.Refresh(userData);
            string tempFilename = System.IO.Path.GetTempFileName();

            Size renderSize = new Size(1280, 720);
            ImageUtil.SaveToBitmap(newControl, tempFilename, renderSize);

            PowerPoint.Shape theShape = slide.Shapes.AddPicture(tempFilename, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoTrue, width / 2.0f, height / 2.0f, width, height);
            

            //Store Section/Page info to the shape
            theShape.Name = @"ActiveDeck_Categories";

            theShape.Tags.Add("Section", mConfig.ParentSlideConfig.SlideId.ToString());
            theShape.Tags.Add("Page", mConfig.PageId.ToString()); //TODO: Get the page business figured out
            theShape.Tags.Add("ConfigType", typeof(CategoriesConfig).ToString());
           
            return theShape;
        }


    }
}
